<!DOCTYPE html>
<html>
<body>

<p>点击按钮循环对象属性。</p>

<button onclick="myFunction()">点我</button>

<p id="demo"></p>

<script>
function myFunction() {
    var person = {fname:"John", lname:"Doe", age:25,a:"1"}; 
    var text = "";
    var i = 1
    for (var k in person) {
        text += person[k] + " ";
        console.log(k)
        console.log(i++)
    }
    document.getElementById("demo").innerHTML = text;
}
</script>

</body>
</html>